package 力扣._7022_判断通过操作能否让字符串相等2;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class Solution {
    public boolean checkStrings(String s1, String s2) {
        Map<Character,Integer> map1_ji = new HashMap<>();
        Map<Character,Integer> map1_ou = new HashMap<>();
        Map<Character,Integer> map2_ji = new HashMap<>();
        Map<Character,Integer> map2_ou = new HashMap<>();
        for (int i = 0; i < s1.length(); i++) {
            if(i%2==0){
                if(map1_ou.containsKey(s1.charAt(i))){
                    map1_ou.put(s1.charAt(i),map1_ou.get(s1.charAt(i))+1);
                }else {
                    map1_ou.put(s1.charAt(i),1);
                }

                if(map2_ou.containsKey(s2.charAt(i))){
                    map2_ou.put(s2.charAt(i),map2_ou.get(s2.charAt(i))+1);
                }else {
                    map2_ou.put(s2.charAt(i),1);
                }

            }else {
                if(map1_ji.containsKey(s1.charAt(i))){
                    map1_ji.put(s1.charAt(i),map1_ji.get(s1.charAt(i))+1);
                }else {
                    map1_ji.put(s1.charAt(i),1);
                }

                if(map2_ji.containsKey(s2.charAt(i))){
                    map2_ji.put(s2.charAt(i),map2_ji.get(s2.charAt(i))+1);
                }else {
                    map2_ji.put(s2.charAt(i),1);
                }
            }
        }
        Set<Character> set1 = map1_ou.keySet();
        for (Character c : set1) {
            if(!map2_ou.containsKey(c)|| !Objects.equals(map1_ou.get(c), map2_ou.get(c)))
                return false;
        }
        Set<Character> set2 = map1_ji.keySet();
        for (Character c : set2) {
            if(!map2_ji.containsKey(c)|| !Objects.equals(map1_ji.get(c), map2_ji.get(c)))
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        boolean b = new Solution().checkStrings("ublnlasppynwgx", "ganplbuylnswpx");
        System.out.println(b);
        //"ublnlasppynwgx"
        //"ganplbuylnswpx"
    }
}
